import request from '@/common/request/request.js'
import config from '@/common/config/config.js';
import store from '@/common/store/index.js'
const http = config.env

export const getUpdateBaseUrl = (url = null) => {
    let baseUrl = {
       'development': 'http://8.130.34.52:7019/stage-saas-api',
       'production': 'https://saas.manage.coudiandian.com.cn/prod-saas-api'
    }
    return url || baseUrl[process.env.NODE_ENV]
}

export const getPlatform = (type) => {
    let platformType = {
       1: "凑点点",
       2: "哈米之恋",
       3: "怀太公",
       4: "啤酒哥",
       5: "珺璟",
       6: "粤数文",
       7: "陈皮大雪山",
       8: "润小纯",
       9: "竹逸商城",
       10: "老周头",
       11: "流转平台",
       0: "未知",
    }
    return platformType[type]
}

export const uploadFile = async (file, platformType) => {
    uni.showLoading({
       title:'上传中...'
    })
    let baseUrl =  http.uploadImg //getUpdateBaseUrl()
    let platform =  platformType //getPlatform(platformType)
    let [err, res] = await uni.uploadFile({
       url: baseUrl + '/common/uploadFile',
       filePath: file,
       name: 'files',
       header:{
          'Authorization': store.state.token
       },
    })
    uni.hideLoading()
    if(res){
       return JSON.parse(res.data)
    }else{
       return err
    }

}